﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MemcachedDemo.Library;
using MemcachedDemo.Library.Config;
using MemcachedDemo.Library.Common;
using MemcachedDemo.Library.Client;
using MemcachedDemo.Library.UnitTests;

namespace MvcDemo.Move.Controllers
{
    public class MemcachedController : Controller
    {
        //
        // GET: /Memcached/
        public ActionResult Index()
        {
            /*
            MemcachedSettings config = new MemcachedSettings();
            config.PoolName = "TestMemcached";
            config.ServerList.Add(new ServerInfo() { Ip = "192.168.1.163" });
            config.ServerList.Add(new ServerInfo() { Ip = "192.168.1.189" });
            var xmlText = SerializerUtility.SerializeToXmlString(config);
            ViewBag.XmlText = xmlText;
            */


            //var mc = MemcachedManager.Instance;
            //mc.Set("A", 123);
            //mc.Set("B", 456);
            //Response.Write(mc.Get("A"));
            //Response.Write("<br/>");
            //mc.FlushAll();
            //Response.Write(mc.Get("A"));
            //mc.GetMultiple(new string[] { "A", "B" });
            //var result = MemcachedManager.GetStatsBy(null, MemcachedStatsCommand.Slabs, string.Empty);
            //Response.Write(result.ToString().Replace("\r\n", "<br/>"));
            //MemcachedManager.Instance.FlushAll();
            Dictionary<string, List<string>> serverCacheKeyList = MemcachedManager.GetAllCacheKeys();

            foreach (var item in serverCacheKeyList)
            {
                item.Value.ForEach(_ =>
                    {
                        Response.Write(MemcachedManager.Instance.Get(_) +"<br/>");
                    });

            }
            //Response.Write(string.Join("", result.ToArray().ToArray<string>()));
            //var severList = new string[] { "192.168.1.189:1211" };
            //var weights = new int[] { 1 };
            //MemcachedClient mc = new MemcachedClient();
            //SockIOPool pool = SockIOPool.GetInstance("TestMemcached");
            //pool.SetServers(severList);
            //pool.SetWeights(weights);


            //pool.Initialize();
            //MemcachedTest.Main(new string[0]{});

            return View();
        }

    }
}
